package com.cmc.cloud.cmclink.doc.controller.admin.special;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.cmc.cloud.cmclink.doc.constants.errorconstant.PartnerSpecialCargoEmailErrorCodeConstants;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.PartnerSpecialCargoEmailConvert;
import com.cmc.cloud.cmclink.doc.entity.PartnerSpecialCargoEmailDO;
import com.cmc.cloud.cmclink.doc.service.PartnerSpecialCargoEmailService;
import com.cmc.cloud.cmclink.doc.vo.special.partneremailvo.PartnerSpecialCargoEmailCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.partneremailvo.PartnerSpecialCargoEmailPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.partneremailvo.PartnerSpecialCargoEmailRespVO;
import com.cmc.cloud.cmclink.doc.vo.special.partneremailvo.PartnerSpecialCargoEmailUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 合作方 Email 维护前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 合作方 Email 维护")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/special/partner-email")
public class PartnerSpecialCargoEmailController {

    @Resource
    private PartnerSpecialCargoEmailService partnerSpecialCargoEmailService;

    @Operation(summary = "创建合作方 Email 维护")
    @PostMapping("/create")
    public CommonResult<Void>
        createPartnerSpecialCargoEmail(@Valid @RequestBody PartnerSpecialCargoEmailCreateReqVO createReqVO) {
        partnerSpecialCargoEmailService.createPartnerSpecialCargoEmail(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新合作方 Email 维护")
    @PostMapping("/update")
    public CommonResult<Void>
        updatePartnerSpecialCargoEmail(@Valid @RequestBody PartnerSpecialCargoEmailUpdateReqVO updateReqVO) {
        partnerSpecialCargoEmailService.updatePartnerSpecialCargoEmail(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除合作方 Email 维护")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deletePartnerSpecialCargoEmail(@PathVariable("id") Long id) {
        partnerSpecialCargoEmailService.deletePartnerSpecialCargoEmail(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得合作方 Email 维护")
    @GetMapping("/get/detail/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @UseResponsePropertyAdvice
    public CommonResult<PartnerSpecialCargoEmailRespVO> getPartnerSpecialCargoEmail(@PathVariable("id") Long id) {
        PartnerSpecialCargoEmailDO partnerSpecialCargoEmail =
            partnerSpecialCargoEmailService.getPartnerSpecialCargoEmail(id);
        if (partnerSpecialCargoEmail == null) {
            throw ServiceExceptionUtil.exception(PartnerSpecialCargoEmailErrorCodeConstants.PARTNER_EMAIL_NOT_EXISTED);
        }
        return CommonResult.success(PartnerSpecialCargoEmailConvert.INSTANCE.convert(partnerSpecialCargoEmail));
    }

    @Operation(summary = "获得合作方 Email 维护分页")
    @PostMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<PartnerSpecialCargoEmailRespVO>>
        getPartnerSpecialCargoEmailPage(@Valid @RequestBody PartnerSpecialCargoEmailPageReqVO pageVO) {
        PageResult<PartnerSpecialCargoEmailDO> pageResult =
            partnerSpecialCargoEmailService.getPartnerSpecialCargoEmailPage(pageVO);
        List<PartnerSpecialCargoEmailRespVO> results =
            PartnerSpecialCargoEmailConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}